home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4232 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: jhunix.hcf.jhu.edu!hbien
  2. From: hbien@jhunix.hcf.jhu.edu (Harold Bien)
  3. Newsgroups: comp.object,comp.lang.c++,comp.ai.alife,sci.comp-aided
  4. Subject: Re: [Q] Growing Objects
  5. Followup-To: comp.object,comp.lang.c++,comp.ai.alife,sci.comp-aided
  6. Date: 28 Jan 1996 05:59:20 GMT
  7. Organization: HCF - Johns Hopkins University, Baltimore, Maryland, USA
  8. Message-ID: <4ef3bo$mjo@news.jhu.edu>
  9. References: <30FE8297.41C6@bme.jhu.edu> <RMARTIN.96Jan20093428@rcm.oma.com>
  10. NNTP-Posting-Host: 128.220.2.5
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Robert C. Martin (rmartin@oma.com) wrote:
  14.  
  15.     [deleted]
  16.  
  17. : What you have described is known as a finite state machine.  A finite
  18. : state machine reacts to particular events in ways that depend upon the
  19. : state of the machine.  In your case, you have only one event: Run; but
  20. : you have many states. 
  21.  
  22.     [deleted]
  23.  
  24. : You can use pointers to member functions to control your state
  25. : machine.  However I recommend against it.  It may be, after some time,
  26. : that you find that you need other events beside 'run'.  For example,
  27. : you may wish to tell each cell to "print"; and would like the behavior
  28. : of "print" to depend upon the state of the cell.  Other events seem
  29. : likely as well:  RespondToLight, RespondToHunger, RespondToAttack,
  30. : etc.  Each of these stimuli will very likely depend upon the state.
  31. : If you use the member function approach, you will find that every time
  32. : the cell changes state, you will have to shuttle around many pointers
  33. : to member functions.  The chances of error are high.
  34.  
  35.     [deleted]
  36.  
  37.      You bring up some interesting points.  Though I readily see the 
  38. logic in your approach, I'm curious as to why my approach is 
  39. "incorrect."  The Run() function is the main function called and will 
  40. dispatch to the changing RealRun() function.  However, the Run() function 
  41. doesn't really do much except call _OTHER_ subfuctions.  Therefore, 
  42. should I need new methods like RespondToLight() et al. I will only have 
  43. to put them in the RealRun() function relevant to the state.  Am I 
  44. overlooking something?  I have yet to implement anything, but am afraid 
  45. of commiting myself to something which will not stand up to the test of 
  46. time.  Thanks for your respons.
  47.